<template>
	<view class="Dynamic">
		<u-navbar title="动态" back-icon-color="#fff" :background="background" title-color="#fff"></u-navbar>
		<view class="u-page">
			<view class="content">
				<view class="list-item" v-for="item in commentList" :key="item.id">
					<view class="personInfo">
						<view class="left">
							<u-avatar :src="src"></u-avatar>
							<text class="name">{{item.userName}}</text>
						</view>
					</view>
					<view class="detail">
						{{item.talk}}
					</view>
				</view>
			</view>
		</view>
		<view class="setCommit">
			<u-input v-model="commentValue" class="input" :type="type" :border="border" />
			<button type="warn" size="mini" @click="comment">评论</button>
		</view>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		data() {
			return {
				background: {},
				textColor: "",
				src: 'static/logo.png',
				commentValue: '',
				type: 'text',
				border: true,
				SCBStyle: {
					fontSize: "30rpx",
				},
				commentList: [],
				controlText: true,
			}
		},
		computed: {
			...mapState({
				commonColor: ({config})=>config.commonColor,
				id: ({config})=>config.id,
				openid: ({config})=>config.openid,
			})
		},
		methods: {
			getCommentList() {
				this.$http.get("/queryDiscuss.htm", {musicId: this.id}).then(res => {
					this.commentList = res.result;
					this.commentList.forEach(item => {
						this.getDiscussComment(item.id);
					})
				})
			},
			getDiscussComment(musicDiscussId) {
				this.$http.get("/queryDiscussComment.htm", {musicDiscussId})
			},
			comment() {
				this.$http.get("/insertDiscuss.htm", {
					musicId: this.id,
					userId: this.openid,
					talk: this.commentValue,
					userName: "天下第一帅",
				}).then(res => {
					this.commentValue = "";
					this.getCommentList();
				})
			}
		},
		created() {
			this.background["backgroundColor"] = this.commonColor;
			this.textColor= this.commonColor;
			this.getCommentList();
		}
	}
</script>

<style lang="less">
	.Dynamic {
		display: flex;
		flex-direction: column;
		height: 100%;
		.u-page {
			flex: 1;
			overflow: hidden;
			.content {
				padding: 20rpx;
				.list-item {
					background-color: #fff;
					border-radius: 10rpx;
					overflow: hidden;
					padding: 20rpx;
					margin-bottom: 30rpx;
					.personInfo {
						display: flex;
						justify-content: space-between;
						align-items: center;
						width: 100%;
						.left {
							display: flex;
							align-items: center;
							.name {
								padding-left: 40rpx;
								font-size: 30rpx;
								letter-spacing: 5rpx;
							}
						}
					}
					.detail {
						padding: 20rpx 0;
						text-indent:2em;
						font-size: 28rpx;
					}
					.comment {
						display: flex;
						align-items: center;
						//justify-content: space-between;
						padding: 20rpx 20rpx;
						.input {
							width: 80%;
							margin-right: 10rpx;
						}
						.mini-btn {
							margin: 15rpx;
						}
					}
					.comment-list {
						padding: 15rpx 0;
						.item {
							display: flex;
							align-items: center;
							padding-bottom: 10rpx;
							font-size: 25rpx;
							padding-left: 30rpx;
							.name {
								padding-left: 10rpx;
							}
						}
					}
				}
			}
		}
	}
	.setCommit {
		position: fixed;
		width: 100%;
		bottom: 0;
		display: flex;
		align-items: center;
		padding: 20rpx 20rpx;
		background-color: #fff;
		.input {
			width: 80%;
			margin-right: 10rpx;
		}
		.mini-btn {
			margin: 15rpx;
		}
	}
</style>
